package day20171010;

import java.util.Scanner;

public class StringPalidrome {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串.");
        String str = sc.nextLine();

        char[] ch = str.toCharArray();  //将字符串转化为对应的数组
        char[] c = str.toCharArray();

        Reverse r = new Reverse();
        r.reverse(ch);

        Print p = new Print();
        p.print(ch, c);
    }
}

//将字符数组进行反转
class Reverse {

    public void reverse(char[] ch) {
        for (int i = 0; i < ch.length / 2; i++) {
            char t = ch[i];
            ch[i] = ch[ch.length - 1 - i];
            ch[ch.length - 1 - i] = t;
        }
    }
}

//将字符数组与反转的数组进行比对判断
class Print {
    public void print(char[] ch, char[] c) {
        int k = -1;
        for (int i = 0; i < ch.length; i++) {
            if (ch[i] == c[i]) {
                k = 0;
            } else
                k = 1;
        }
        if (k == 0) {
            System.out.println("这是回文");
        } else {
            System.out.println("这不是回文");
        }
    }
}